home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-11-19 | 4.5 KB | 186 lines | [TEXT/MPS ] |
- !!MP inlines.f
- c This example shows How To
- c
- c • save the output window to a datafile
- c
- c • count the number of selected (highlighted) characters
- c
- c • display the selected (highlighted) characters
- c
- c Example provided for owners of Language Systems FORTRAN
- c © 1990 Language Systems Corp.
- c
-
- C There are two changes you need to make to MPW:Interfaces:FIncludes:Textedit.f.
- C Move the definitions for Chars, CharsPtr, and CharsHandle in front of the
- C definition for TERec. In the structure definition for TERec, change hText from
- C Record /Handle/ hText to Record/ CharsHandle/ hText.
-
- program OutputWindowTricks
- implicit none
-
- write(*,*)
- write(*,*) 'This program illustrates the Following Output Window Tricks'
- write(*,*)
- write(*,*) ' • How to save the output window to a datafile'
- write(*,*)
- write(*,*) ' • How to count the number of selected (highlighted) characters'
- write(*,*)
- write(*,*) ' • How to display the selected (highlighted) characters'
- write(*,*)
-
- Call ADDMENUITEM('Tricks','Save Data File',Saveit)
- Call ADDMENUITEM('Tricks','Display Selection',DisplaySelection)
- Call ADDMENUITEM('Tricks','Count Characters in Selection',DisplayCharCount)
-
- call DOMENU('Edit','Select All')
- call DOMENU('Tricks','Count Characters in Selection')
- end
-
- c ***************************************************************************
- c
- c Saveit -
- c This subroutine illustrates how to save the contents
- c of the output window to a file.
- c
- subroutine Saveit
- implicit none
- include 'textedit.f'
-
- record /TEHandle/ wintext
- Record /CharsHandle/ mytexth
- Character*32000 mytext
- Integer*4 OUTPUTTE, L, LL
- external OUTPUTTE
-
- c set up to access the window text
-
- wintext.TEH = OUTPUTTE()
- mytexth = wintext.TEH^.TEP^.hText
-
- c lock the handle so that it doesn't move
-
- Call HLock(mytexth)
-
- c use a local variable to access each character
- c and print them to a file
-
- mytext = mytexth.CHH^.CHP^.chs
- LL = wintext.TEH^.TEP^.teLength
- open(1,file=*'Save output window to file',status = 'new')
- write(1,'($A)') (mytext(L:L),L=1,LL)
- close(1)
-
- call HUnlock(mytexth)
- return
-
- end
- c
- c How to speed up SaveIt
- c
- c The characters that are stored in the TEHandle are formatted.
- c Because of this, the toolbox call FSWRITE can be used
- c instead of the FORTRAN write.
- c
- c To change the program to use an FSWRITE do the following:
- c
- c • add these declarations
- c
- c integer*2 refnum
- c integer*4 JFREFNUM
- c external JFREFNUM
- c
- c • remove the line
- c
- c mytext = mytexth.CHH^.CHP^.chs
- c
- c • replace the line
- c
- c write(1,'($A)') (mytext(L:L),L=1,LL)
- c
- c with
- c
- c refnum = JFREFNUM(int4(1))
- c if (FSWrite(refnum,%ref(LL),mytexth.CHH^.CHP^) <> 0) call ALERTBOX('Write error')
- c
-
- c ***************************************************************************
- c
- c Function ReturnSelection
- c This function returns the characters that are
- c selected (highlighted) in the output window.
- c The selection could be up to 32K in length.
- c
- character*(*) function ReturnSelection()
- implicit none
- include 'textedit.f'
-
- record /TEHandle/ wintext
- Record /CharsHandle/ mytexth
- Integer*4 OUTPUTTE
- external OUTPUTTE
- pointer /character*1/ chptr
-
- c set up to access the window text
-
- wintext.TEH = OUTPUTTE()
- mytexth = wintext.TEH^.TEP^.hText
-
- c lock the handle so that it doesn't move
-
- Call HLock(mytexth)
-
- c use a local pointer to access the selected/highlighted characters
-
- chptr = wintext.TEH^.TEP^.hText.CHH^.CHP
- ReturnSelection = chptr^(wintext.TEH^.TEP^.selStart+1:wintext.TEH^.TEP^.selEnd)
-
- call HUnlock(mytexth)
- return
- end
-
- c ***************************************************************************
- c
- c Function CountSelChars
- c This function returns the number of characters that are
- c selected (highlighted) in the output window.
- c
- integer*4 function CountSelChars()
- implicit none
- include 'textedit.f'
-
- record /TEHandle/ wintext
- Integer*4 OUTPUTTE
- external OUTPUTTE
-
- wintext.TEH = OUTPUTTE()
- Call HLock(wintext)
- CountSelChars = wintext.TEH^.TEP^.selEnd - wintext.TEH^.TEP^.selStart
- call HUnlock(wintext)
- return
- end
-
- c ***************************************************************************
-
- subroutine DisplayCharCount
- implicit none
-
- character*20 numChars
- integer*4 CountSelChars
-
- write(numChars,'(i)') CountSelChars()
- call ALERTBOX('There were '//trim(numChars)//' Characters Selected')
- end
-
- c ***************************************************************************
- !!stack=32767
-
- subroutine DisplaySelection
- implicit none
-
- character*32000 ReturnSelection
-
- call ALERTBOX(trim(ReturnSelection()))
- end
-
-